package com.qf.news.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.news.entity.NewsDetail;
import com.qf.news.mapper.NewsDetailMapper;
import com.qf.news.service.NewsDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Administrator
 * @version V1.0
 * @Project spring_news
 * @Package com.qf.news.service.impl
 * @Description: ${TODO}
 * @Date 2021/10/3 17:48
 */

@Service
public class NewsDetailServiceImpl implements NewsDetailService {

    @Autowired
    private NewsDetailMapper newsDetailMapper;

    @Override
    @Transactional
    public void deleteById(Integer id) {
        int i = newsDetailMapper.deleteByPrimaryKey(id);
        if (i != 1){
            throw new RuntimeException("删除失败");
        }
    }

    @Override
    public List<NewsDetail> findAll() {
        return newsDetailMapper.selectByExample(null);
    }

    @Override
    public PageInfo<NewsDetail> findByNameAndPage(Integer pageNum, Integer pageSize, String name) {

        PageHelper.startPage(pageNum, pageSize);
        List<NewsDetail> list = newsDetailMapper.selectByName(name);
        PageInfo<NewsDetail> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
